local skynet = require "skynet"

local env = {
    MONGO_PER_CONN     = tonumber(skynet.getenv "MONGO_PER_CONN"),
    MYSQL_PER_CONN     = tonumber(skynet.getenv "MYSQL_PER_CONN"),
    LOGIN_PORT         = tonumber(skynet.getenv "LOGIN_PORT"),
    PAY_PORT           = tonumber(skynet.getenv "PAY_PORT"),
    CMS_PORT           = tonumber(skynet.getenv "CMS_PORT"),
    DEBUG_CONSOLE_PORT = tonumber(skynet.getenv "DEBUG_CONSOLE_PORT"),
    MONGO_PORT         = tonumber(skynet.getenv "MONGO_PORT"),
    MYSQL_PORT         = tonumber(skynet.getenv "MYSQL_PORT"),
    MAX_LOGINING       = tonumber(skynet.getenv "MAX_LOGINING"),
    HTTP_GATE_HOST     = tonumber(skynet.getenv "HTTP_GATE_HOST"),
    HTTP_GATE_PORT     = tonumber(skynet.getenv "HTTP_GATE_PORT"),
    HTTP_GATE_PRELOAD  = tonumber(skynet.getenv "HTTP_GATE_PRELOAD"),
    WS_GATE_HOST       = tonumber(skynet.getenv "WS_GATE_HOST"),
    WS_GATE_PORT       = tonumber(skynet.getenv "WS_GATE_PORT"),
    WS_GATE_PRELOAD    = tonumber(skynet.getenv "WS_GATE_PRELOAD"),
    MAX_CLIENT         = tonumber(skynet.getenv "MAX_CLIENT"),
    DEBUG              = skynet.getenv "DEBUG" and true or false,
    ALERT_ENABLE       = skynet.getenv "ALERT_ENABLE" and true or false,
}

return setmetatable(env, {
    __newindex = function()
        error("env cannot write")
    end,
    __index = function(t, k)
        local v = rawget(t, k)
        if v then
            return v
        else
            return skynet.getenv(k)
        end
    end
})
